package com.msk.web.controller.wlhy.goodsMember;

import com.alibaba.fastjson2.JSONObject;
import com.msk.base.domain.goodsMember.GoodsMember;
import com.msk.base.service.goodsMember.GoodsMemberService;
import com.msk.common.core.controller.BaseController;
import com.msk.common.core.domain.R;
import com.msk.common.core.domain.model.LoginUser;
import com.msk.common.utils.StringUtils;
import com.msk.framework.web.utils.TokenUtils;
import com.msk.sys.domain.User;
import com.msk.sys.service.SystemService;
import com.msk.wlhy.domain.HtCompany;
import com.msk.wlhy.service.HtCompanyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Api(tags = "货主接口")
@RestController
@RequestMapping("/api/goodsMember")
public class GoodsMemberController  extends BaseController {

    @Autowired
    private GoodsMemberService goodsMemberService;
    @Autowired
    private SystemService systemService;

    @Autowired
    private HtCompanyService htCompanyService;
    /**
     * @Description 货主认证信息
     * @Author wlxiang
     * @Date 10:34 2023/6/7
     * @Param
     * @param params
     * @return com.msk.common.core.domain.R<?>
     **/
    @ApiOperation("货主认证信息")
    @PostMapping("/getGoodsMemberInfo")
    public R<?> getGoodsMemberInfo(@RequestBody Map<String,Object> params) {
        String id = StringUtils.getString(params.get("id"));
        String userId = null;
        if(StringUtils.isBlank(id)){
            LoginUser loginUser = TokenUtils.getMpLoginUser();
            userId = loginUser.getLoginId();
        }
        //请求参数校验
        if(StringUtils.isBlank(id)&&StringUtils.isBlank(userId)){
            return  R.appFail(400101,"请求参数异常");
        }
        Map<String,Object> goodsMemberInfo = goodsMemberService.selectGoodsMemberInfoById(id,userId);
        return R.appOk(goodsMemberInfo);
    }

    /**
     * @Description 企业货主认证
     * @Author wlxiang
     * @Date 10:25 2023/6/5
     * @Param
     * @param params
     * @return com.msk.common.core.domain.R<?>
     **/
    @ApiOperation("企业货主认证")
    @PostMapping("/enterpriseGoodsMemberCertification")
    public R<?> enterpriseGoodsMemberCertification(@RequestBody Map<String,Object> params) {
        LoginUser loginUser = TokenUtils.getMpLoginUser();
        GoodsMember goodsMember = goodsMemberService.getByLoginId(loginUser.getLoginId());
        String id = "";
        if(StringUtils.isNull(goodsMember)){
            goodsMember = new GoodsMember();
        }else if(!"1".equalsIgnoreCase(goodsMember.getMemberType())){
            id = goodsMember.getId();
            goodsMember = new GoodsMember();
            goodsMember.setId(id);
        }
        goodsMember.setUserId(loginUser.getLoginId());
        goodsMember.setMemberType("1");
        //身份证信息
        //营业执照、身份证照片
        String picture = StringUtils.getString(params.get("picture"));
        goodsMember.setPicture(picture);
        //公司名称
        String comName = StringUtils.getString(params.get("comName"));
        goodsMember.setComName(comName);
        //社会统一代码
        String unifiedSocialCode =  StringUtils.getString(params.get("unifiedSocialCode"));
        goodsMember.setUnifiedSocialCode(unifiedSocialCode);
        //所在区域(code)
        String gmArea =   StringUtils.getString(params.get("gmArea"));
        goodsMember.setGmArea(gmArea);
        //详细地址
        String detailAddress =  StringUtils.getString(params.get("detailAddress"));
        goodsMember.setDetailAddress(detailAddress);
        //一般纳税人
        String generalTaxpayer =   StringUtils.getString(params.get("generalTaxpayer"));
        goodsMember.setGeneralTaxpayer(generalTaxpayer);
        //法人身份证信息
        //法人身份证正面（国徽）
        String legalIdCardFront = StringUtils.getString(params.get("legalIdCardFront"));
        goodsMember.setLegalIdCardFront(legalIdCardFront);
        //法人身份证反面（人像）
        String legalIdCardBack = StringUtils.getString(params.get("legalIdCardBack"));
        goodsMember.setLegalIdCardBack(legalIdCardBack);
        //法人姓名
        String legelName =  StringUtils.getString(params.get("legelName"));
        goodsMember.setLegelName(legelName);
        //法人电话
        String legelPhone =  StringUtils.getString(params.get("legelPhone"));
        goodsMember.setLegelPhone(legelPhone);
        //法人身份证
        String legalIdCardNo =  StringUtils.getString(params.get("legalIdCardNo"));
        goodsMember.setLegalIdCardNo(legalIdCardNo);

        //联系人身份证信息
        //联系人姓名
        String contactsName =  StringUtils.getString(params.get("contactsName"));
        goodsMember.setContactsName(contactsName);
        //联系人电话
        String contactsPhone =  StringUtils.getString(params.get("contactsPhone"));
        goodsMember.setContactsPhone(contactsPhone);
        //委托书
        String letterAttorney =  StringUtils.getString(params.get("letterAttorney"));
        goodsMember.setLetterAttorney(letterAttorney);

        //账户信息
        //开户行名称
        String baseOpenAccountName = StringUtils.getString(params.get("baseOpenAccountName"));
        goodsMember.setBaseOpenAccountName(baseOpenAccountName);
        //开户行账号
        String baseOpenAccountInfo = StringUtils.getString(params.get("baseOpenAccountInfo"));
        goodsMember.setBaseOpenAccountInfo(baseOpenAccountInfo);
        //开户行地址
        String baseOpenAddress =  StringUtils.getString(params.get("baseOpenAddress"));
        goodsMember.setBaseOpenAddress(baseOpenAddress);
        //开户行类别
        String baseOpenType =  StringUtils.getString(params.get("baseOpenType"));
        goodsMember.setBaseOpenType(baseOpenType);
        //
        User user = systemService.getUser(goodsMember.getUserId());
        if(legelName==null){
            legelName = "";
        }
        if(goodsMember!=null && StringUtils.isBlank(goodsMember.getName()))
            goodsMember.setName(legelName);
        goodsMember.setUser(user);
        goodsMember.setAuditStatus("0");
        goodsMember.setMobile(user.getMobile());

        Map<String,Object> resultMap = this.checkEnterpriseParams(goodsMember);
        if(!("1".equalsIgnoreCase(resultMap.get("code").toString()))){
            return  R.appFail(Integer.parseInt(StringUtils.getString(resultMap.get("code"))),resultMap.get("msg").toString());
        }
        goodsMember.setAuditStatus("0");
        goodsMemberService.saveNew(goodsMember);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("flag",1);
        jsonObject.put("msh","认证成功");
        return R.appOk(jsonObject);
    }

    @ApiOperation("企业货主保存")
    @PostMapping("/enterpriseGoodsMemberSave")
    public R<?> enterpriseGoodsMemberSave(@RequestBody Map<String,Object> params) {
        LoginUser loginUser = TokenUtils.getMpLoginUser();
        GoodsMember goodsMember = goodsMemberService.getByLoginId(loginUser.getLoginId());
        String id = "";
        if(StringUtils.isNull(goodsMember)){
            goodsMember = new GoodsMember();
        }else if(!"1".equalsIgnoreCase(goodsMember.getMemberType())){
            id = goodsMember.getId();
            goodsMember = new GoodsMember();
            goodsMember.setId(id);
        }
        goodsMember.setUserId(loginUser.getLoginId());
        goodsMember.setMemberType("1");
        Integer page = Integer.parseInt(StringUtils.getString(params.get("page")));
        for(int i = page;i >0 ; i--){
            //第一页
            if(2== i){
                //身份证信息
                //营业执照、身份证照片
                String picture = StringUtils.getString(params.get("picture"));
                goodsMember.setPicture(picture);
                //公司名称
                String comName = StringUtils.getString(params.get("comName"));
                goodsMember.setComName(comName);
                //社会统一代码
                String unifiedSocialCode =  StringUtils.getString(params.get("unifiedSocialCode"));
                goodsMember.setUnifiedSocialCode(unifiedSocialCode);
                //所在区域(code)
                String gmArea =   StringUtils.getString(params.get("gmArea"));
                goodsMember.setGmArea(gmArea);
                //详细地址
                String detailAddress =  StringUtils.getString(params.get("detailAddress"));
                goodsMember.setDetailAddress(detailAddress);
                //一般纳税人
                String generalTaxpayer =   StringUtils.getString(params.get("generalTaxpayer"));
                goodsMember.setGeneralTaxpayer(generalTaxpayer);
            }else if(3== i){
                //法人身份证信息
                //法人身份证正面（国徽）
                String legalIdCardFront = StringUtils.getString(params.get("legalIdCardFront"));
                goodsMember.setLegalIdCardFront(legalIdCardFront);
                //法人身份证反面（人像）
                String legalIdCardBack = StringUtils.getString(params.get("legalIdCardBack"));
                goodsMember.setLegalIdCardBack(legalIdCardBack);
                //法人姓名
                String legelName =  StringUtils.getString(params.get("legelName"));
                goodsMember.setLegelName(legelName);
                if(legelName==null){
                    legelName = "";
                }
                if(goodsMember!=null && StringUtils.isBlank(goodsMember.getName())){
                    goodsMember.setName(legelName);
                }
                //法人电话
                String legelPhone =  StringUtils.getString(params.get("legelPhone"));
                goodsMember.setLegelPhone(legelPhone);
                //法人身份证
                String legalIdCardNo =  StringUtils.getString(params.get("legalIdCardNo"));
                goodsMember.setLegalIdCardNo(legalIdCardNo);

                //联系人身份证信息
                //联系人姓名
                String contactsName =  StringUtils.getString(params.get("contactsName"));
                goodsMember.setContactsName(contactsName);
                //联系人电话
                String contactsPhone =  StringUtils.getString(params.get("contactsPhone"));
                goodsMember.setContactsPhone(contactsPhone);
                //委托书
                String letterAttorney =  StringUtils.getString(params.get("letterAttorney"));
                goodsMember.setLetterAttorney(letterAttorney);

            }else if(4== i){
                //账户信息
                //开户行名称
                String baseOpenAccountName = StringUtils.getString(params.get("baseOpenAccountName"));
                goodsMember.setBaseOpenAccountName(baseOpenAccountName);
                //开户行账号
                String baseOpenAccountInfo = StringUtils.getString(params.get("baseOpenAccountInfo"));
                goodsMember.setBaseOpenAccountInfo(baseOpenAccountInfo);
                //开户行地址
                String baseOpenAddress =  StringUtils.getString(params.get("baseOpenAddress"));
                goodsMember.setBaseOpenAddress(baseOpenAddress);
                //开户行类别
                String baseOpenType =  StringUtils.getString(params.get("baseOpenType"));
                goodsMember.setBaseOpenType(baseOpenType);
            }
        }


        User user = systemService.getUser(goodsMember.getUserId());
        goodsMember.setUser(user);
        goodsMember.setMobile(user.getMobile());
        goodsMemberService.saveOnly(goodsMember);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("flag",1);
        jsonObject.put("msh","保存成功");
        return R.appOk(jsonObject);
    }

    /**
     * @Description  个人货主认证
     * @Author wlxiang
     * @Date 10:40 2023/6/5
     * @Param
     * @param params
     * @return com.msk.common.core.domain.R<?>
     **/
    @ApiOperation("个人货主认证")
    @PostMapping("/personalGoodsMemberCertification")
    public R<?> personalGoodsMemberCertification(@RequestBody Map<String,Object> params) {
        LoginUser loginUser = TokenUtils.getMpLoginUser();
        GoodsMember goodsMember = goodsMemberService.getByLoginId(loginUser.getLoginId());
        String id = "";
        if(StringUtils.isNull(goodsMember)){
            goodsMember = new GoodsMember();
            goodsMember.setUserId(loginUser.getLoginId());
        }else {
            if(!"0".equalsIgnoreCase(goodsMember.getMemberType())){
                id = goodsMember.getId();
                goodsMember = new GoodsMember();
                goodsMember.setId(id);
                goodsMember.setUserId(loginUser.getLoginId());
            }
        }
        goodsMember.setUserId(loginUser.getLoginId());
        goodsMember.setMemberType("0");
        //身份证信息
        //自然人身份证反面（人像）
        String idCardFront = StringUtils.getString(params.get("idCardFront"));
        goodsMember.setIdCardFront(idCardFront);
        //自然人身份证反面（人像）
        String idCardBack = StringUtils.getString(params.get("idCardBack"));
        goodsMember.setIdCardBack(idCardBack);
        //姓名
        String name =  StringUtils.getString(params.get("name"));
        goodsMember.setName(name);
        goodsMember.setContactsName(name);
        //联系人电话
        String contactsPhone =  StringUtils.getString(params.get("contactsPhone"));
        goodsMember.setContactsPhone(contactsPhone);
        //身份证号码
        String cardNo =  StringUtils.getString(params.get("cardNo"));
        goodsMember.setCardNo(cardNo);
        //所在区域(code)
        String gmArea =   StringUtils.getString(params.get("gmArea"));
        goodsMember.setGmArea(gmArea);
        //详细地址
        String detailAddress =  StringUtils.getString(params.get("detailAddress"));
        goodsMember.setDetailAddress(detailAddress);
        //账户信息
        //开户行名称
        String baseOpenAccountName = StringUtils.getString(params.get("baseOpenAccountName"));
        goodsMember.setBaseOpenAccountName(baseOpenAccountName);
        //开户行账号
        String baseOpenAccountInfo = StringUtils.getString(params.get("baseOpenAccountInfo"));
        goodsMember.setBaseOpenAccountInfo(baseOpenAccountInfo);
        //开户行地址
        String baseOpenAddress =  StringUtils.getString(params.get("baseOpenAddress"));
        goodsMember.setBaseOpenAddress(baseOpenAddress);
        //开户行类别
        String baseOpenType =  StringUtils.getString(params.get("baseOpenType"));
        goodsMember.setBaseOpenType(baseOpenType);
        Map<String,Object> resultMap = this.checkPersonalParams(goodsMember);
        if(!("1".equalsIgnoreCase(resultMap.get("code").toString()))){
            return  R.appFail(Integer.parseInt(StringUtils.getString(resultMap.get("code"))),resultMap.get("msg").toString());
        }
        User user = systemService.getUser(goodsMember.getUserId());
        goodsMember.setUser(user);
        goodsMember.setAuditStatus("0");
        goodsMember.setMobile(user.getMobile());
        goodsMemberService.saveNew(goodsMember);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("flag",1);
        jsonObject.put("msh","认证成功");
        return R.appOk(jsonObject);
    }

    @ApiOperation("个人货主保存")
    @PostMapping("/personalGoodsMemberSave")
    public R<?> personalGoodsMemberSave(@RequestBody Map<String,Object> params) {
        LoginUser loginUser = TokenUtils.getMpLoginUser();
        String id = "";
        GoodsMember goodsMember = goodsMemberService.getByLoginId(loginUser.getLoginId());
        if(StringUtils.isNull(goodsMember)){
            goodsMember = new GoodsMember();
        }else {
            if(!"0".equalsIgnoreCase(goodsMember.getMemberType())){
                id = goodsMember.getId();
                goodsMember = new GoodsMember();
                goodsMember.setId(id);
            }
        }
        goodsMember.setUserId(loginUser.getLoginId());
        Integer page = Integer.parseInt(StringUtils.getString(params.get("page")));
        goodsMember.setMemberType("0");
        for(int i = page;i >0 ; i--){
            //第一页
            if(2== i){
                //身份证信息
                //自然人身份证反面（人像）
                String idCardFront = StringUtils.getString(params.get("idCardFront"));
                goodsMember.setIdCardFront(idCardFront);
                //自然人身份证反面（人像）
                String idCardBack = StringUtils.getString(params.get("idCardBack"));
                goodsMember.setIdCardBack(idCardBack);
                //姓名
                String name =  StringUtils.getString(params.get("name"));
                goodsMember.setName(name);
                goodsMember.setContactsName(name);
                //联系人电话
                String contactsPhone =  StringUtils.getString(params.get("contactsPhone"));
                goodsMember.setContactsPhone(contactsPhone);
                //身份证号码
                String cardNo =  StringUtils.getString(params.get("cardNo"));
                goodsMember.setCardNo(cardNo);
                //所在区域(code)
                String gmArea =   StringUtils.getString(params.get("gmArea"));
                goodsMember.setGmArea(gmArea);
                //详细地址
                String detailAddress =  StringUtils.getString(params.get("detailAddress"));
                goodsMember.setDetailAddress(detailAddress);

            }else if(3== i){
                //账户信息
                //开户行名称
                String baseOpenAccountName = StringUtils.getString(params.get("baseOpenAccountName"));
                goodsMember.setBaseOpenAccountName(baseOpenAccountName);
                //开户行账号
                String baseOpenAccountInfo = StringUtils.getString(params.get("baseOpenAccountInfo"));
                goodsMember.setBaseOpenAccountInfo(baseOpenAccountInfo);
                //开户行地址
                String baseOpenAddress =  StringUtils.getString(params.get("baseOpenAddress"));
                goodsMember.setBaseOpenAddress(baseOpenAddress);
                //开户行类别
                String baseOpenType =  StringUtils.getString(params.get("baseOpenType"));
                goodsMember.setBaseOpenType(baseOpenType);
            }
        }
        User user = systemService.getUser(goodsMember.getUserId());
        goodsMember.setUser(user);
        goodsMember.setMobile(user.getMobile());
        goodsMemberService.saveOnly(goodsMember);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("flag",1);
        jsonObject.put("msh","保存成功");
        return R.appOk(jsonObject);
    }

    /**
     * @Description 货主认证状态查询
     * @Author wlxiang
     * @Date 17:16 2023/6/5
     * @param params
     * @return com.msk.common.core.domain.R<?>
     **/
    @ApiOperation("货主认证状态查询")
    @PostMapping("/getGoodsMemberAuditInfo")
    public R<?> getGoodsMemberAuditInfo(@RequestBody Map<String,Object> params) {
        String id = StringUtils.getString(params.get("id"));
        String loginId = null;
        if(StringUtils.isBlank(id)){
            LoginUser loginUser = TokenUtils.getMpLoginUser();
            loginId = loginUser.getLoginId();
        }
        //请求参数校验
        if(StringUtils.isBlank(id)&&StringUtils.isBlank(loginId)){
            return  R.appFail(400101,"请求参数异常");
        }
        //货主审批状态查询
        Map<String,Object> result = goodsMemberService.selectAuditInfoById(id,loginId);
        return R.appOk(result);
    }

    /**
     * @Description 企业货主认证参数校验
     * @Author wlxiang
     * @Date 11:45 2023/6/5
     * @Param 
     * @param goodsMember
     * @return java.util.Map<java.lang.String,java.lang.Object>
     **/
    private Map<String,Object> checkEnterpriseParams(GoodsMember goodsMember){
        Map<String,Object> result = new HashMap<>();
        if(StringUtils.isBlank(goodsMember.getPicture())){
            String msg = "参数营业执照#picture为空";
            result.put("msg",msg);
            result.put("code",400501);
            return result;
        }
        //公司名称
        if(StringUtils.isBlank(goodsMember.getComName())){
            String msg = "参数公司名称#comName为空";
            result.put("msg",msg);
            result.put("code",400502);
            return result;
        }
        if(StringUtils.isBlank(goodsMember.getUnifiedSocialCode())){
            String msg = "参数社会统一代码#unifiedSocialCode为空";
            result.put("msg",msg);
            result.put("code",400503);
            return result;
        }
        if(StringUtils.isBlank(goodsMember.getGmArea())){
            String msg = "参数所在区域#gmArea为空";
            result.put("msg",msg);
            result.put("code",400504);
            return result;
        }
        //
        if(StringUtils.isBlank(goodsMember.getDetailAddress())){
            String msg = "参数详细地址#detailAddress为空";
            result.put("msg",msg);
            result.put("code",400505);
            return result;
        }
        if(StringUtils.isBlank(goodsMember.getGeneralTaxpayer())){
            String msg = "参数纳税人证明#generalTaxpayer为空";
            result.put("msg",msg);
            result.put("code",400506);
            return result;
        }
        if(StringUtils.isBlank(goodsMember.getLegalIdCardFront())){
            String msg = "参数法人身份证正面#legalIdCardFront为空";
            result.put("msg",msg);
            result.put("code",400507);
            return result;
        }
        if(StringUtils.isBlank(goodsMember.getLegalIdCardBack())){
            String msg = "参数法人身份证反面#legalIdCardBack";
            result.put("msg",msg);
            result.put("code",400508);
            return result;
        }
        //
        if(StringUtils.isBlank(goodsMember.getLegelName())){
            String msg = "参数法人姓名#legelName";
            result.put("msg",msg);
            result.put("code",400509);
            return result;
        }
        //法人电话
        if(StringUtils.isBlank(goodsMember.getLegelPhone())){
            String msg = "参数法人电话#legelPhone";
            result.put("msg",msg);
            result.put("code",400510);
            return result;
        }
        //
        if(StringUtils.isBlank(goodsMember.getLegalIdCardNo())){
            String msg = "参数法人身份证#legalIdCardNo";
            result.put("msg",msg);
            result.put("code",400511);
            return result;
        }
        //联系人身份证信息
        if(StringUtils.isBlank(goodsMember.getContactsName())){
            String msg = "参数联系人姓名#contactsName";
            result.put("msg",msg);
            result.put("code",400512);
            return result;
        }
        //联系人电话
        if(StringUtils.isBlank(goodsMember.getContactsPhone())){
            String msg = "参数联系人电话#contactsPhone";
            result.put("msg",msg);
            result.put("code",400513);
            return result;
        }
        //
        if(StringUtils.isBlank(goodsMember.getLetterAttorney())){
            String msg = "参数委托书#letterAttorney";
            result.put("msg",msg);
            result.put("code",400514);
            return result;
        }
        //账户信息
        if(StringUtils.isBlank(goodsMember.getBaseOpenAccountName())){
            String msg = "参数开户行名称#baseOpenAccountName";
            result.put("msg",msg);
            result.put("code",400515);
            return result;
        }
        //
        if(StringUtils.isBlank(goodsMember.getBaseOpenAccountInfo())){
            String msg = "参数开户行账号#baseOpenAccountInfo";
            result.put("msg",msg);
            result.put("code",4005135);
            return result;
        }
        //开户行地址
        if(StringUtils.isBlank(goodsMember.getBaseOpenAddress())){
            String msg = "参数开户行地址#baseOpenAddress";
            result.put("msg",msg);
            result.put("code",400517);
            return result;
        }
        result.put("code",1);
        return result;
    }

    /**
     * @Description 企业货主认证参数校验
     * @Author wlxiang
     * @Date 11:45 2023/6/5
     * @Param
     * @param goodsMember
     * @return java.util.Map<java.lang.String,java.lang.Object>
     **/
    private Map<String,Object> checkPersonalParams(GoodsMember goodsMember){
        Map<String,Object> result = new HashMap<>();
        if(StringUtils.isBlank(goodsMember.getIdCardFront())){
            String msg = "参数自然人身份证正面#idCardFront";
            result.put("msg",msg);
            result.put("code",400521);
            return result;
        }
        if(StringUtils.isBlank(goodsMember.getIdCardBack())){
            String msg = "参数身份证反面#idCardBack";
            result.put("msg",msg);
            result.put("code",400520);
            return result;
        }
        //
        if(StringUtils.isBlank(goodsMember.getName())){
            String msg = "参数姓名#name";
            result.put("msg",msg);
            result.put("code",400519);
            return result;
        }
        //联系人电话
        if(StringUtils.isBlank(goodsMember.getContactsPhone())){
            String msg = "参数联系人电话#contactsPhone";
            result.put("msg",msg);
            result.put("code",400513);
            return result;
        }
        //身份证号码
        if(StringUtils.isBlank(goodsMember.getCardNo())){
            String msg = "参数所在区域#cardNo为空";
            result.put("msg",msg);
            result.put("code",4005018);
            return result;
        }

        if(StringUtils.isBlank(goodsMember.getGmArea())){
            String msg = "参数所在区域#gmArea为空";
            result.put("msg",msg);
            result.put("code",400504);
            return result;
        }
        //
        if(StringUtils.isBlank(goodsMember.getDetailAddress())){
            String msg = "参数详细地址#detailAddress为空";
            result.put("msg",msg);
            result.put("code",400505);
            return result;
        }

        //账户信息
        if(StringUtils.isBlank(goodsMember.getBaseOpenAccountName())){
            String msg = "参数开户行名称#baseOpenAccountName";
            result.put("msg",msg);
            result.put("code",400515);
            return result;
        }
        //
        if(StringUtils.isBlank(goodsMember.getBaseOpenAccountInfo())){
            String msg = "参数开户行账号#baseOpenAccountInfo";
            result.put("msg",msg);
            result.put("code",4005135);
            return result;
        }
        //开户行地址
        if(StringUtils.isBlank(goodsMember.getBaseOpenAddress())){
            String msg = "参数开户行地址#baseOpenAddress";
            result.put("msg",msg);
            result.put("code",400517);
            return result;
        }
        result.put("code",1);
        return result;
    }

    /**
     * @Description 我的收货方列表
     * @Author wlxiang
     * @Date 19:03 2023/6/9
     * @Param 
     * @param params
     * @return com.msk.common.core.domain.R<?>
     **/
    @ApiOperation("我的收货方列表")
    @PostMapping("/getRecipientList")
    public R<?> getRecipientList(@RequestBody Map<String,Object> params) {
        String affiliatedPersonId = StringUtils.getString(params.get("affiliatedPersonId"));
        if(StringUtils.isBlank(affiliatedPersonId)){
            return R.appFail(400101, "请求参数所属人ID#affiliatedPersonId为空");
        }
        String consigneeName = StringUtils.getString(params.get("consigneeName"));
        List<Map<String,Object>> recipientList = htCompanyService.selectRecipientList(affiliatedPersonId,consigneeName);
        return R.appOk(recipientList);
    }

    /**
     * @Description 新增我的收货方
     * @Author wlxiang
     * @Date 14:12 2023/6/12
     * @Param 
     * @param params
     * @return com.msk.common.core.domain.R<?>
     **/
    @ApiOperation("新增我的收货方")
    @PostMapping("/addRecipient")
    public R<?> addRecipient(@RequestBody Map<String,Object> params) {
        String affiliatedPersonId = StringUtils.getString(params.get("affiliatedPersonId"));
        if(StringUtils.isBlank(affiliatedPersonId)){
            return R.appFail(400101, "请求参数所属人ID#affiliatedPersonId为空");
        }
        String consigneeName = StringUtils.getString(params.get("consigneeName"));
        if(StringUtils.isBlank(consigneeName)){
            return R.appFail(400101, "请求参数收货方公司/个人名称#consigneeName为空");
        }
        String contact1User = StringUtils.getString(params.get("contact1User"));
        if(StringUtils.isBlank(contact1User)){
            return R.appFail(400101, "请求参数收货人姓名#contact1User为空");
        }
        String contactNumber1 = StringUtils.getString(params.get("contactNumber1"));
        if(StringUtils.isBlank(contactNumber1)){
            return R.appFail(400101, "请求参数收货人联系电话#contactNumber1为空");
        }
        HtCompany htCompany = new HtCompany();
       // htCompany.preInsert();
        htCompany.setCompanyName(consigneeName);
        htCompany.setContacts2(contact1User);
        htCompany.setContactNumber2(contactNumber1);
        htCompany.setUseType("2");
        htCompany.setAffiliatedPersonId(affiliatedPersonId);

        htCompanyService.save(htCompany);
        return R.appOk(htCompany);
    }

    /**
     * @Description 编辑我的收货方
     * @Author wlxiang
     * @Date 14:37 2023/6/12
     * @Param 
     * @param params
     * @return com.msk.common.core.domain.R<?>
     **/
    @ApiOperation("编辑我的收货方")
    @PostMapping("/updateRecipient")
    public R<?> updateRecipient(@RequestBody Map<String,Object> params) {
        String id = StringUtils.getString(params.get("id"));
        if(StringUtils.isBlank(id)){
            return R.appFail(400101, "请求参数收货方ID#id为空");
        }

        String consigneeName = StringUtils.getString(params.get("consigneeName"));
        if(StringUtils.isBlank(consigneeName)){
            return R.appFail(400101, "请求参数收货方公司/个人名称#consigneeName为空");
        }
        String contact1User = StringUtils.getString(params.get("contact1User"));
        if(StringUtils.isBlank(contact1User)){
            return R.appFail(400101, "请求参数收货人姓名#contact1User为空");
        }
        String contactNumber1 = StringUtils.getString(params.get("contactNumber1"));
        if(StringUtils.isBlank(contactNumber1)){
            return R.appFail(400101, "请求参数收货人联系电话#contactNumber1为空");
        }
        LoginUser loginUser = TokenUtils.getMpLoginUser();
        params.put("updateBy",loginUser.getLoginId());
        int i = htCompanyService.updateRecipient(params);
        return R.appOk(params);
    }

    /**
     * @Description 删除我的收货方
     * @Author wlxiang
     * @Date 14:51 2023/6/12
     * @Param
     * @param params
     * @return com.msk.common.core.domain.R<?>
     **/
    @ApiOperation("删除我的收货方")
    @PostMapping("/deleteRecipient")
    public R<?> deleteRecipient(@RequestBody Map<String,Object> params) {
        String id = StringUtils.getString(params.get("id"));
        if(StringUtils.isBlank(id)){
            return R.appFail(400101, "请求参数收货方ID#id为空");
        }
        htCompanyService.delete(new HtCompany(id));
        return R.appOk(params);
    }
    
    /**
     * @author llh
     * @date 2023/6/21
     * @return com.msk.common.core.domain.R<?>
     * @description 运单数据统计      
     */
    @ApiOperation("运单数据统计")
    @PostMapping("/dataStatistics")
    public R<?> dataStatistics(@RequestBody Map<String,Object> map){
        if(TokenUtils.getGoodsMemberLogin() == null){
            return R.appFail(400101,"用户未认证");
        }
        LoginUser loginUser = TokenUtils.getMpLoginUser();
        User user = new User();
        if(loginUser != null){
            user = systemService.getUser(loginUser.getLoginId());
        }
        String companyId = user.getCompany().getId();
        String status = String.valueOf(map.get("status"));
        String startDate = null;
        String endDate = null;
        if (status != null && "3".equals(status)) {
            startDate = String.valueOf(map.get("startDate"));
            endDate = String.valueOf(map.get("endDate"));
            endDate += " 23:59:59";
        }
        Map<String,Integer> resultMap = goodsMemberService.getGoodsData(companyId, status, startDate, endDate);
        return R.appOk(resultMap);
    }
}
